-- CALC_CAVE_BONUS_12

-- 计算怪物巢穴副本奖励
-- @param user    玩家对象
-- @param args    奖励计算参数
-- @param grade   副本难度
-- @param layer   地牢层数
return function(user, args, grade, layer)
    -- caution：如果修改该公式，服务器请一并修改

    -- grade : 副本难度
    -- layer : 地牢层数
    local maxHp = 0;
    local randSeed  = DungeonM.getRandSeed("DUNGEON_CAVE12");
    local randSeed2 = DungeonM.getRandSeed("DUNGEON_CAVE12");
    local arr, arr2 = {}, {};

    if grade == INSTANCE_GRADE_HARD then
        maxHp = 20;
        arr2   = { { ["class_id"] = 1103, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 水晶+floor/20
                   { ["class_id"] = 1105, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 魂晶+floor/20
                   { ["class_id"] = 1107, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 奥晶+floor/20
                   { ["class_id"] = 1109, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 }, };    -- 圣晶+floor/20
        arr    = { { ["class_id"] = 5091, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“真理挂坠”×1
                   { ["class_id"] = 5092, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“真理之靴”×1
                   { ["class_id"] = 5093, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“真理之戒”×1
                   { ["class_id"] = 5094, ["amount"] = 1, ["ratio"] = 100, }, };                                    -- 宝物“真理披肩”×1
    elseif grade == INSTANCE_GRADE_DIFFICULT then
        maxHp = 10;
        arr2   = { { ["class_id"] = 1103, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 水晶+floor/20
                   { ["class_id"] = 1105, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },       -- 魂晶+floor/20
                   { ["class_id"] = 1107, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 }, };    -- 奥晶+floor/20
        arr    = { { ["class_id"] = 5081, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“混沌护符”×1
                   { ["class_id"] = 5082, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“混沌之靴”×1
                   { ["class_id"] = 5083, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“混沌之戒”×1
                   { ["class_id"] = 5084, ["amount"] = 1, ["ratio"] = 100, }, };                                    -- 宝物“混沌披风”×1
    elseif grade == INSTANCE_GRADE_NORMAL then
        arr2   = { { ["class_id"] = 1103, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 },        -- 水晶+floor/20
                   { ["class_id"] = 1105, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 }, };     -- 魂晶+floor/20
        arr    = { { ["class_id"] = 5071, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“符文挂坠”×1
                   { ["class_id"] = 5072, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“符文靴”×1
                   { ["class_id"] = 5073, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“符文戒指”×1
                   { ["class_id"] = 5074, ["amount"] = 1, ["ratio"] = 100, }, };                                    -- 宝物“符文斗篷”×1
    else
        arr2   = { { ["class_id"] = 1103, ["amount"] = math.max(1, math.modf(layer / 20)), ["ratio"] = 100 }, };    -- 水晶+floor/20
        arr    = { { ["class_id"] = 5061, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“法师护符”×1
                   { ["class_id"] = 5062, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“法师鞋”×1
                   { ["class_id"] = 5063, ["amount"] = 1, ["ratio"] = 100, },                                       -- 宝物“法师戒指”×1
                   { ["class_id"] = 5064, ["amount"] = 1, ["ratio"] = 100, }, };                                    -- 宝物“法师斗篷”×1
    end

    local ret = {};
    local bonus;

    if maxHp > 0 then
        -- 属性奖励
        table.insert(ret, { 2, "max_hp", maxHp, });
    end

    if #arr2 > 0 then
        -- 物品奖励
        bonus = fetchElemBySeed(arr2, randSeed);
        table.insert(ret, { 1, bonus["class_id"], bonus["amount"], });
    end

    if #arr > 0 then
        -- 物品奖励
        bonus = fetchElemBySeed(arr, randSeed2);
        table.insert(ret, { 1, bonus["class_id"], bonus["amount"], });
    end

    return ret;
end